local GameMath = {}

local math = math

function GameMath.normalize(x,y)
	if(x == 0 and y == 0)
	then
		return x,y
	end

	local length = GameMath.length(x,y)
	local nx = x/length
	local ny = y/length
	return nx,ny
end

function GameMath.length(x,y)
	--print(x,y)
	local length = x * x + y * y
	length = math.sqrt(length)
	--print(length)
	return length
end

function GameMath.floor(x)
	local r

	if(x <= 0) then
		r = math.ceil(x)
	else
		r = math.ceil(x)
		if(r ~= x) then
			r = r - 1
		end
	end

	return r
end

function GameMath.limit(x, min, max)
	if(min > max) then
		print("GameMath.limit min is bigger than max!")
		return x
	end

	if(x < min) then
		x = min
	end

	if(x > max) then
		x = max
	end

	return x
end

return GameMath